ARG PHP_IMAGE
FROM ${PHP_IMAGE}

ARG TZ
ARG PHP_EXTENSIONS
ARG CONTAINER_PACKAGE_URL

RUN if [ $CONTAINER_PACKAGE_URL ] ; then sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories ; fi

ADD --chmod=0755 ./install-php-extensions  /usr/local/bin/

ENV IPE_ICU_EN_ONLY=1 
ENV IPE_LZF_BETTERCOMPRESSION=1
RUN install-php-extensions ${PHP_EXTENSIONS}

RUN apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
    && echo "$TZ" > /etc/timezone

# Fix: https://github.com/docker-library/php/issues/240
RUN apk add gnu-libiconv libstdc++ --no-cache --repository http://${CONTAINER_PACKAGE_URL}/alpine/edge/community/ --allow-untrusted
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

# Install composer and change it's cache home
# RUN curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
#     && chmod +x /usr/bin/composer
# ENV COMPOSER_HOME=/tmp/composer
RUN curl -fsSL https://getcomposer.org/installer -o composer-installer.php \
    && php composer-installer.php --install-dir=/usr/local/bin --filename=composer \
    && composer clear-cache \
    && composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php \
    && rm composer-installer.php \
    || { echo "Composer installation failed"; exit 1; }


RUN apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data

# 配置工作目录
WORKDIR /app
# 容器卷
VOLUME /app
# 暴露端口
EXPOSE 8787